// document.cookie="token=9054ac6ec8e52ac96eabce12b47c2946db1fc0e9"
getCookie=function(name){ 
	var arr=document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
	if(arr!=null)return unescape(arr[2]); return "";
}
var token= getCookie("token");
var pagelimit = 20;

function pages(count, limit){
	var page = 0;
	if(count>0){

		var page = Math.ceil(count/limit);

		var pagetag = "";
		for (var k=1;k<=page;k++) {
			if(k==1){
				pagetag += '<li><a href="#" style="background:#ccc">'+k+'</a></li>';
			}else{
				pagetag += '<li><a href="#" >'+k+'</a></li>';
			}

		}
		if(page<=1){
			var pagetag = "";
		}
		$('.pagination').html(pagetag);

	}


}
$(function(){
    //
	////	获取个人资料
	//$.ajax({
	//	url:'http://ww.yc630.com/api/index.php/Buyer/User/userinfo',
	//	type:"post",
	//	data:{
	//		'token':token
	//	},
	//	dataType:"JSON",
	//	success:function(data){
	//		var avatar = data['data']['avatar'];
	//		if(avatar==''){
	//			avatar = '../img/Group%2019.png';
	//		}
	//		$("#headPic").attr('src',avatar)
	//	}
	//})
	//左侧菜单悬停
	$(".list_menu li").hover(function(){
		var index=$(this).index()
		if(index==0||index==5||index==8){
			$(this).css('backgroundColor','#ffffff')
		}
		else {
			$(this).css('backgroundColor','#FEE631')
		}
	},function(){
		var index=$(this).index()
		if(index==1){
			$(this).css('backgroundColor','#FEE631')
		}
		else{
			$(this).css('backgroundColor','#ffffff')
		}
	})
	//获得商家信息
	$.ajax({
		type:"post",
		url:"http://ww.yc630.com/api/index.php/Buyer/Goods/sellerdetail",
		data:{
			'token':token
		},
		dataType:'json',
		success:function(data){
			$("#icon_img").attr('src',data.data.icon_image)
			$("#icon_name").html(data.data.name)
		}
	});

	//获得品牌列表
	$.ajax({
		type:"post",
		url:"http://ww.yc630.com/api/index.php/Seller/Goods/brandist",
		data:{
			'token':token
		},
		dataType:'json',
		success:function(phpdata){
			var str = '';
			for(i in phpdata['data']){
				
				 str += '<option value="'+i+'">'+phpdata['data'][i]+'</option>';				
			}

			$('select[name="brand"]').append(str);
		}
		
	});
	//获得人群风格
	$.ajax({
		type:"post",
		url:"http://ww.yc630.com/api/index.php/Seller/Goods/peopleStylelist",
		data:{
			'token':token
		},
		dataType:'json',
		success:function(phpdata){
			var str = '';
			for(i in phpdata['data']){
				
				 str += '<option value="'+i+'">'+phpdata['data'][i]+'</option>';				
			}

			$('select[name="people_style"]').append(str);
			
		}
	});
	//获得风格列表
	$('select[name="people_style"]').change(function(){
		var people_style = $(this).val();
		$('select[name="goods_style"]').html('<option value="">按风格筛选</option>');
		if(people_style == 0){
			$('select[name="goods_style"]').html('<option value="">按风格筛选</option>');
			return false;
		}
		$.ajax({
			type:"post",
			url:"http://ww.yc630.com/api/index.php/Seller/Goods/goodsStylelist",
			data:{'people_style':people_style,'token':token},
			dataType:'json',
			success:function(phpdata){
				var str = '';
				for(i in phpdata['data']){
					
					 str += '<option value="'+i+'">'+phpdata['data'][i]+'</option>';				
				}
	
				$('select[name="goods_style"]').append(str);
			}
		});
	})
	
	//根据条件筛选
	$('select[name="brand"]').change(function(){
		//获取各种条件
		var brand = $('select[name="brand"]').val();
		var goods_style = $('select[name="goods_style"]').val();
		var people_style = $('select[name="people_style"]').val();
		var status = $('select[name="status"]').val();
		var status_html = $('select[name="status"]').find("option:selected").text();
		
		var data = {};
		if(brand!=0){
			data['brand']=brand;
		}
		if(people_style !=0 && goods_style !=0){
			data['people_style']=people_style;
			data['goods_style']=goods_style;
		}
		if(status != ''){
			data['status']=status+status_html;
		}
		data['page']=1;
		data['pagelimit']=pagelimit;
		data['token']=token
		$.ajax({
			type:"post",
			url:"http://ww.yc630.com/api/index.php/Seller/Goods/goodsList",
			data:data,
			dataType:'json',
			success:function(phpdata){
				//分页
				pages(phpdata['data']['count'],pagelimit);
				
				var str = '<tr class="z_head"><td>序号</td><td>商品ID</td><td>商品名称</td><td>价格</td><td>品牌</td><td>人群</td><td>风格</td><td id="store_nu">库存↑↓</td><td id="sell_nu">累计销量↑↓</td><td id="viewnu">浏览次数↑↓</td><td id="purchase_nu">加入购物车↑↓</td><td id="saved">收藏</td><td>状态</td><td>操作</td></tr>';
			if(phpdata['data']['count']==0){					
				str += '<tr><td colspan="14" style="color:#999">暂无搜索结果</td></tr>';
				$('.z_t').html(str);
				return false;
			}
			for(i in phpdata['data']['goods']){
				j=i*1+1*1;
				var status_name = '';
				var make = '';
				if(phpdata['data']['goods'][i]['status'] == 0){
					var status_name = '未提交';
					var make = '<a onclick="gcommit(this)">提交</a> <a onclick="edit(this)">编辑</a> <a onclick="delet(this)">删除</a>'
				}
				if(phpdata['data']['goods'][i]['status']==1){
					var status_name = '审核中';
					var make = '<a onclick="edit(this)">编辑</a> <a onclick="delet(this)">删除</a>';
				}
				if(phpdata['data']['goods'][i]['status']==2){
					var status_name = '未通过';
					var make = '<a onclick="edit(this)">编辑</a> <a onclick="delet(this)">删除</a>';
				}
				if(phpdata['data']['goods'][i]['status']==3){
					var status_name = '代售';
					var make = '<a onclick="sj(this)">上架</a> <a onclick="edit(this)">编辑</a> <a onclick="delet(this)">删除</a>';
				}
				if(phpdata['data']['goods'][i]['status']==4){
					var status_name = '已上架';
					var make = '<a onclick="xj(this)">下架</a> <a onclick="edit(this)">编辑</a> <a onclick="delet(this)">删除</a>';
				}
				if(phpdata['data']['goods'][i]['status']==5){
					var status_name = '已下架';
					var make = '<a onclick="sj(this)">上架</a> <a onclick="edit(this)">编辑</a> <a onclick="delet(this)">删除</a>';
				}
				if(phpdata['data']['goods'][i]['status']==6){
					var status_name = '被删除';
					var make = '';
				}
				str += '<tr class="z_list_main"><td>'+j+'</td><td>'+phpdata['data']['goods'][i]['id']+'</td><td>'+phpdata['data']['goods'][i]['goods_name']+'</td><td>'+phpdata['data']['goods'][i]['min_price']+'-'+phpdata['data']['goods'][i]['max_price']+'</td><td>'+phpdata['data']['goods'][i]['brand_name']+'</td><td>'+phpdata['data']['goods'][i]['people_style_name']+'</td><td>'+phpdata['data']['goods'][i]['goods_style_name']+'</td><td>'+phpdata['data']['goods'][i]['store_nu']+'</td><td>'+phpdata['data']['goods'][i]['sell_nu']+'</td><td>'+phpdata['data']['goods'][i]['viewnu']+'</td><td>'+phpdata['data']['goods'][i]['purchase_nu']+'</td><td>'+phpdata['data']['goods'][i]['notice_nu']+'</td><td>'+status_name+'</td><td>'+make+'</td></tr>';
			}
			$('.z_t').html(str);
			}

		});
						
	})
	
	
	$('select[name="status"]').change(function(){
		//获取各种条件
		var brand = $('select[name="brand"]').val();
		var goods_style = $('select[name="goods_style"]').val();
		var people_style = $('select[name="people_style"]').val();
		var status = $('select[name="status"]').val();
		var status_html = $('select[name="status"]').find("option:selected").text();
		
		var data = {};
		if(brand!=0){
			data['brand']=brand;
		}
		if(people_style !=0 && goods_style !=0){
			data['people_style']=people_style;
			data['goods_style']=goods_style;
		}
		if(status != ''){
			data['status']=status+status_html;
		}
		
		data['page']=1;
		data['pagelimit']=pagelimit;
		data['token']=token
		
		$.ajax({
			type:"post",
			url:"http://ww.yc630.com/api/index.php/Seller/Goods/goodsList",
			data:data,
			dataType:'json',
			success:function(phpdata){
				
				//分页
				pages(phpdata['data']['count'],pagelimit);
				
				var str = '<tr class="z_head"><td>序号</td><td>商品ID</td><td>商品名称</td><td>价格</td><td>品牌</td><td>人群</td><td>风格</td><td id="store_nu">库存↑↓</td><td id="sell_nu">累计销量↑↓</td><td id="viewnu">浏览次数↑↓</td><td id="purchase_nu">加入购物车↑↓</td><td id="saved">收藏</td><td>状态</td><td>操作</td></tr>';
			if(phpdata['data']['count']==0){					
				str += '<tr><td colspan="14" style="color:#999">暂无搜索结果</td></tr>';
				$('.z_t').html(str);
				return false;
			}
			for(i in phpdata['data']['goods']){
				j=i*1+1*1;
				var status_name = '';
				var make = '';
				if(phpdata['data']['goods'][i]['status'] == 0){
					var status_name = '未提交';
					var make = '<a onclick="gcommit(this)">提交</a> <a onclick="edit(this)">编辑</a> <a onclick="delet(this)">删除</a>'
				}
				if(phpdata['data']['goods'][i]['status']==1){
					var status_name = '审核中';
					var make = '<a onclick="edit(this)">编辑</a> <a onclick="delet(this)">删除</a>';
				}
				if(phpdata['data']['goods'][i]['status']==2){
					var status_name = '未通过';
					var make = '<a onclick="edit(this)">编辑</a> <a onclick="delet(this)">删除</a>';
				}
				if(phpdata['data']['goods'][i]['status']==3){
					var status_name = '代售';
					var make = '<a onclick="sj(this)">上架</a> <a onclick="edit(this)">编辑</a> <a onclick="delet(this)">删除</a>';
				}
				if(phpdata['data']['goods'][i]['status']==4){
					var status_name = '已上架';
					var make = '<a onclick="xj(this)">下架</a> <a onclick="edit(this)">编辑</a> <a onclick="delet(this)">删除</a>';
				}
				if(phpdata['data']['goods'][i]['status']==5){
					var status_name = '已下架';
					var make = '<a onclick="sj(this)">上架</a> <a onclick="edit(this)">编辑</a> <a onclick="delet(this)">删除</a>';
				}
				if(phpdata['data']['goods'][i]['status']==6){
					var status_name = '被删除';
					var make = '';
				}
				str += '<tr class="z_list_main"><td>'+j+'</td><td>'+phpdata['data']['goods'][i]['id']+'</td><td>'+phpdata['data']['goods'][i]['goods_name']+'</td><td>'+phpdata['data']['goods'][i]['min_price']+'-'+phpdata['data']['goods'][i]['max_price']+'</td><td>'+phpdata['data']['goods'][i]['brand_name']+'</td><td>'+phpdata['data']['goods'][i]['people_style_name']+'</td><td>'+phpdata['data']['goods'][i]['goods_style_name']+'</td><td>'+phpdata['data']['goods'][i]['store_nu']+'</td><td>'+phpdata['data']['goods'][i]['sell_nu']+'</td><td>'+phpdata['data']['goods'][i]['viewnu']+'</td><td>'+phpdata['data']['goods'][i]['purchase_nu']+'</td><td>'+phpdata['data']['goods'][i]['notice_nu']+'</td><td>'+status_name+'</td><td>'+make+'</td></tr>';
			}
			$('.z_t').html(str);
			}

		});
						
	})
	
	
	$('select[name="goods_style"]').change(function(){
		//获取各种条件
		var brand = $('select[name="brand"]').val();
		var goods_style = $('select[name="goods_style"]').val();
		var people_style = $('select[name="people_style"]').val();
		var status = $('select[name="status"]').val();
		var status_html = $('select[name="status"]').find("option:selected").text();
		
		var data = {};
		if(brand!=0){
			data['brand']=brand;
		}
		if(people_style !=0 && goods_style !=0){
			data['people_style']=people_style;
			data['goods_style']=goods_style;
		}
		if(status != ''){
			data['status']=status+status_html;
		}
		
		data['page']=1;
		data['pagelimit']=pagelimit;
		data['token']=token
		
		$.ajax({
			type:"post",
			url:"http://ww.yc630.com/api/index.php/Seller/Goods/goodsList",
			data:data,
			dataType:'json',
			success:function(phpdata){
				//分页
				pages(phpdata['data']['count'],pagelimit);
				var str = '<tr class="z_head"><td>序号</td><td>商品ID</td><td>商品名称</td><td>价格</td><td>品牌</td><td>人群</td><td>风格</td><td id="store_nu">库存↑↓</td><td id="sell_nu">累计销量↑↓</td><td id="viewnu">浏览次数↑↓</td><td id="purchase_nu">加入购物车↑↓</td><td id="saved">收藏</td><td>状态</td><td>操作</td></tr>';
			if(phpdata['data']['count']==0){					
				str += '<tr><td colspan="14" style="color:#999">暂无搜索结果</td></tr>';
				$('.z_t').html(str);
				return false;
			}
			for(i in phpdata['data']['goods']){
				j=i*1+1*1;
				var status_name = '';
				var make = '';
				if(phpdata['data']['goods'][i]['status'] == 0){
					var status_name = '未提交';
					var make = '<a onclick="gcommit(this)">提交</a> <a onclick="edit(this)">编辑</a> <a onclick="delet(this)">删除</a>'
				}
				if(phpdata['data']['goods'][i]['status']==1){
					var status_name = '审核中';
					var make = '<a onclick="edit(this)">编辑</a> <a onclick="delet(this)">删除</a>';
				}
				if(phpdata['data']['goods'][i]['status']==2){
					var status_name = '未通过';
					var make = '<a onclick="edit(this)">编辑</a> <a onclick="delet(this)">删除</a>';
				}
				if(phpdata['data']['goods'][i]['status']==3){
					var status_name = '代售';
					var make = '<a onclick="sj(this)">上架</a> <a onclick="edit(this)">编辑</a> <a onclick="delet(this)">删除</a>';
				}
				if(phpdata['data']['goods'][i]['status']==4){
					var status_name = '已上架';
					var make = '<a onclick="xj(this)">下架</a> <a onclick="edit(this)">编辑</a> <a onclick="delet(this)">删除</a>';
				}
				if(phpdata['data']['goods'][i]['status']==5){
					var status_name = '已下架';
					var make = '<a onclick="sj(this)">上架</a> <a onclick="edit(this)">编辑</a> <a onclick="delet(this)">删除</a>';
				}
				if(phpdata['data']['goods'][i]['status']==6){
					var status_name = '被删除';
					var make = '';
				}
				str += '<tr class="z_list_main"><td>'+j+'</td><td>'+phpdata['data']['goods'][i]['id']+'</td><td>'+phpdata['data']['goods'][i]['goods_name']+'</td><td>'+phpdata['data']['goods'][i]['min_price']+'-'+phpdata['data']['goods'][i]['max_price']+'</td><td>'+phpdata['data']['goods'][i]['brand_name']+'</td><td>'+phpdata['data']['goods'][i]['people_style_name']+'</td><td>'+phpdata['data']['goods'][i]['goods_style_name']+'</td><td>'+phpdata['data']['goods'][i]['store_nu']+'</td><td>'+phpdata['data']['goods'][i]['sell_nu']+'</td><td>'+phpdata['data']['goods'][i]['viewnu']+'</td><td>'+phpdata['data']['goods'][i]['purchase_nu']+'</td><td>'+phpdata['data']['goods'][i]['notice_nu']+'</td><td>'+status_name+'</td><td>'+make+'</td></tr>';
			}
			$('.z_t').html(str);
			}

		});
						
	})
	
	
	//商品库列表
	$.ajax({
		type:"post",
		url:"http://ww.yc630.com/api/index.php/Seller/Goods/goodsList",
		data:{'page':1,'pagelimit':pagelimit,'token':token},
		dataType:'json',
		success:function(phpdata){
			//分页
			pages(phpdata['data']['count'],pagelimit);
			var str = '<tr class="z_head"><td>序号</td><td>商品ID</td><td>商品名称</td><td>价格</td><td>品牌</td><td>人群</td><td>风格</td><td id="store_nu">库存↑↓</td><td id="sell_nu">累计销量↑↓</td><td id="viewnu">浏览次数↑↓</td><td id="purchase_nu">加入购物车↑↓</td><td id="saved">收藏</td><td>状态</td><td>操作</td></tr>';
			if(phpdata['data']['count']==0){
				str += '<tr><td colspan="14" style="color:#999">暂无搜索结果</td></tr>';
				$('.z_t').html(str);
				return false;
			}
			for(i in phpdata['data']['goods']){
				j=i*1+1*1;
				var status_name = '';
				var make = '';
				if(phpdata['data']['goods'][i]['status'] == 0){
					var status_name = '未提交';
					var make = '<a onclick="gcommit(this)">提交</a> <a onclick="edit(this)">编辑</a> <a onclick="delet(this)">删除</a>'
				}
				if(phpdata['data']['goods'][i]['status']==1){
					var status_name = '审核中';
					var make = '<a onclick="edit(this)">编辑</a> <a onclick="delet(this)">删除</a>';
				}
				if(phpdata['data']['goods'][i]['status']==2){
					var status_name = '未通过';
					var make = '<a onclick="edit(this)">编辑</a> <a onclick="delet(this)">删除</a>';
				}
				if(phpdata['data']['goods'][i]['status']==3){
					var status_name = '代售';
					var make = '<a onclick="sj(this)">上架</a> <a onclick="edit(this)">编辑</a> <a onclick="delet(this)">删除</a>';
				}
				if(phpdata['data']['goods'][i]['status']==4){
					var status_name = '已上架';
					var make = '<a onclick="xj(this)">下架</a> <a onclick="edit(this)">编辑</a> <a onclick="delet(this)">删除</a>';
				}
				if(phpdata['data']['goods'][i]['status']==5){
					var status_name = '已下架';
					var make = '<a onclick="sj(this)">上架</a> <a onclick="edit(this)">编辑</a> <a onclick="delet(this)">删除</a>';
				}
				if(phpdata['data']['goods'][i]['status']==6){
					var status_name = '被删除';
					var make = '';
				}
				str += '<tr class="z_list_main"><td>'+j+'</td><td>'+phpdata['data']['goods'][i]['id']+'</td><td>'+phpdata['data']['goods'][i]['goods_name']+'</td><td>'+phpdata['data']['goods'][i]['min_price']+'-'+phpdata['data']['goods'][i]['max_price']+'</td><td>'+phpdata['data']['goods'][i]['brand_name']+'</td><td>'+phpdata['data']['goods'][i]['people_style_name']+'</td><td>'+phpdata['data']['goods'][i]['goods_style_name']+'</td><td>'+phpdata['data']['goods'][i]['store_nu']+'</td><td>'+phpdata['data']['goods'][i]['sell_nu']+'</td><td>'+phpdata['data']['goods'][i]['viewnu']+'</td><td>'+phpdata['data']['goods'][i]['purchase_nu']+'</td><td>'+phpdata['data']['goods'][i]['notice_nu']+'</td><td>'+status_name+'</td><td>'+make+'</td></tr>';
			}
			$('.z_t').html(str);

		}
	});
	
	$('.find_commit').click(function(){
		
		var searchvalue = $('input[name="searchvalue"]').val();

		$('select[name="brand"]').get(0).selectedIndex=0;
		$('select[name="people_style"]').get(0).selectedIndex=0;
		$('select[name="people_style"]').get(0).selectedIndex=0;
		$('select[name="goods_style"]').html('<option value="">按风格筛选</option>');
		$('select[name="status"]').get(0).selectedIndex=0;
		if(searchvalue == ''){
			location.reload();
		}
		var data ={};
		data['page']=1;
		data['pagelimit']=pagelimit;
		data['searchvalue']=searchvalue
		data['token']=token
		$.ajax({
			type:"post",
			url:"http://ww.yc630.com/api/index.php/Seller/Goods/goodsList",
			data:data,
			dataType:'json',
			success:function(phpdata){
				//分页
			    pages(phpdata['data']['count'],pagelimit);
				
				var str = '<tr class="z_head"><td>序号</td><td>商品ID</td><td>商品名称</td><td>价格</td><td>品牌</td><td>人群</td><td>风格</td><td id="store_nu">库存↑↓</td><td id="sell_nu">累计销量↑↓</td><td id="viewnu">浏览次数↑↓</td><td id="purchase_nu">加入购物车↑↓</td><td id="saved">收藏</td><td>状态</td><td>操作</td></tr>';
			if(phpdata['data']['count']==0){					
				str += '<tr><td colspan="14" style="color:#999">暂无搜索结果</td></tr>';
				$('.z_t').html(str);
				return false;
			}
			for(i in phpdata['data']['goods']){
				j=i*1+1*1;
				var status_name = '';
				var make = '';
				if(phpdata['data']['goods'][i]['status'] == 0){
					var status_name = '未提交';
					var make = '<a onclick="gcommit(this)">提交</a> <a onclick="edit(this)">编辑</a> <a onclick="delet(this)">删除</a>'
				}
				if(phpdata['data']['goods'][i]['status']==1){
					var status_name = '审核中';
					var make = '<a onclick="edit(this)">编辑</a> <a onclick="delet(this)">删除</a>';
				}
				if(phpdata['data']['goods'][i]['status']==2){
					var status_name = '未通过';
					var make = '<a onclick="edit(this)">编辑</a> <a onclick="delet(this)">删除</a>';
				}
				if(phpdata['data']['goods'][i]['status']==3){
					var status_name = '代售';
					var make = '<a onclick="sj(this)">上架</a> <a onclick="edit(this)">编辑</a> <a onclick="delet(this)">删除</a>';
				}
				if(phpdata['data']['goods'][i]['status']==4){
					var status_name = '已上架';
					var make = '<a onclick="xj(this)">下架</a> <a onclick="edit(this)">编辑</a> <a onclick="delet(this)">删除</a>';
				}
				if(phpdata['data']['goods'][i]['status']==5){
					var status_name = '已下架';
					var make = '<a onclick="sj(this)">上架</a> <a onclick="edit(this)">编辑</a> <a onclick="delet(this)">删除</a>';
				}
				if(phpdata['data']['goods'][i]['status']==6){
					var status_name = '被删除';
					var make = '';
				}
				str += '<tr class="z_list_main"><td>'+j+'</td><td>'+phpdata['data']['goods'][i]['id']+'</td><td>'+phpdata['data']['goods'][i]['goods_name']+'</td><td>'+phpdata['data']['goods'][i]['min_price']+'-'+phpdata['data']['goods'][i]['max_price']+'</td><td>'+phpdata['data']['goods'][i]['brand_name']+'</td><td>'+phpdata['data']['goods'][i]['people_style_name']+'</td><td>'+phpdata['data']['goods'][i]['goods_style_name']+'</td><td>'+phpdata['data']['goods'][i]['store_nu']+'</td><td>'+phpdata['data']['goods'][i]['sell_nu']+'</td><td>'+phpdata['data']['goods'][i]['viewnu']+'</td><td>'+phpdata['data']['goods'][i]['purchase_nu']+'</td><td>'+phpdata['data']['goods'][i]['notice_nu']+'</td><td>'+status_name+'</td><td>'+make+'</td></tr>';
			}
			$('.z_t').html(str);
			}
		});
	})
	
	$('.z_new_add').click(function(){
		location.href="./goods_add.html"
	})
	
	
	$('.pagination').on('click','li a',function(){
		
		//获取当前页码
		var pagenum = $(this).html();
		//改变背景颜色
		$(this).css('background','#ccc');
		$(this).parents('li').siblings('li').find('a').css('background','#FFF')
		
		//获取各种条件
		var brand = $('select[name="brand"]').val();
		var goods_style = $('select[name="goods_style"]').val();
		var people_style = $('select[name="people_style"]').val();
		var status = $('select[name="status"]').val();
		var status_html = $('select[name="status"]').find("option:selected").text();
		
		var searchvalue = $('input[name="searchvalue"]').val();
		var data = {};
		if(searchvalue == ''){
			if(brand!=0){
				data['brand']=brand;
				document.cookie="sort=0";
			}
			if(people_style !=0 && goods_style !=0){
				data['people_style']=people_style;
				data['goods_style']=goods_style;
				document.cookie="sort=0";
			}
			if(status != ''){
				data['status']=status+status_html;
				document.cookie="sort=0";
			}
		}else{
			
			data['searchvalue']=searchvalue;
			document.cookie="sort=0";
			
		}
		var sorts= getCookie("sort");
		if(sorts != 0){

          var name= getCookie(sorts);
         
          if(name==2){	          
	          data['ordercolum']=sorts;
	          data['ordertype']='desc';
			}else{
				
				data['ordercolum']=sorts;
	            data['ordertype']='asc';			
			}
		}

		
		
		data['page']=pagenum;
		data['pagelimit']=pagelimit;
		data['token']=token
		$.ajax({
			type:"post",
			url:"http://ww.yc630.com/api/index.php/Seller/Goods/goodsList",
			data:data,
			dataType:'json',
			success:function(phpdata){
				
				var str = '<tr class="z_head"><td>序号</td><td>商品ID</td><td>商品名称</td><td>价格</td><td>品牌</td><td>人群</td><td>风格</td><td id="store_nu">库存↑↓</td><td id="sell_nu">累计销量↑↓</td><td id="viewnu">浏览次数↑↓</td><td id="purchase_nu">加入购物车↑↓</td><td id="saved">收藏</td><td>状态</td><td>操作</td></tr>';
			if(phpdata['data']['count']==0){					
				str += '<tr><td colspan="14" style="color:#999">暂无搜索结果</td></tr>';
				$('.z_t').html(str);
				return false;
			}
			for(i in phpdata['data']['goods']){
				j=i*1+1*1;
				var status_name = '';
				var make = '';
				if(phpdata['data']['goods'][i]['status'] == 0){
					var status_name = '未提交';
					var make = '<a onclick="gcommit(this)">提交</a> <a onclick="edit(this)">编辑</a> <a onclick="delet(this)">删除</a>'
				}
				if(phpdata['data']['goods'][i]['status']==1){
					var status_name = '审核中';
					var make = '<a onclick="edit(this)">编辑</a> <a onclick="delet(this)">删除</a>';
				}
				if(phpdata['data']['goods'][i]['status']==2){
					var status_name = '未通过';
					var make = '<a onclick="edit(this)">编辑</a> <a onclick="delet(this)">删除</a>';
				}
				if(phpdata['data']['goods'][i]['status']==3){
					var status_name = '代售';
					var make = '<a onclick="sj(this)">上架</a> <a onclick="edit(this)">编辑</a> <a onclick="delet(this)">删除</a>';
				}
				if(phpdata['data']['goods'][i]['status']==4){
					var status_name = '已上架';
					var make = '<a onclick="xj(this)">下架</a> <a onclick="edit(this)">编辑</a> <a onclick="delet(this)">删除</a>';
				}
				if(phpdata['data']['goods'][i]['status']==5){
					var status_name = '已下架';
					var make = '<a onclick="sj(this)">上架</a> <a onclick="edit(this)">编辑</a> <a onclick="delet(this)">删除</a>';
				}
				if(phpdata['data']['goods'][i]['status']==6){
					var status_name = '被删除';
					var make = '';
				}
				str += '<tr class="z_list_main"><td>'+j+'</td><td>'+phpdata['data']['goods'][i]['id']+'</td><td>'+phpdata['data']['goods'][i]['goods_name']+'</td><td>'+phpdata['data']['goods'][i]['min_price']+'-'+phpdata['data']['goods'][i]['max_price']+'</td><td>'+phpdata['data']['goods'][i]['brand_name']+'</td><td>'+phpdata['data']['goods'][i]['people_style_name']+'</td><td>'+phpdata['data']['goods'][i]['goods_style_name']+'</td><td>'+phpdata['data']['goods'][i]['store_nu']+'</td><td>'+phpdata['data']['goods'][i]['sell_nu']+'</td><td>'+phpdata['data']['goods'][i]['viewnu']+'</td><td>'+phpdata['data']['goods'][i]['purchase_nu']+'</td><td>'+phpdata['data']['goods'][i]['notice_nu']+'</td><td>'+status_name+'</td><td>'+make+'</td></tr>';
			}
			$('.z_t').html(str);
			}
		});
				
	})
	//排序
	function sort(name,sorttype){

		$('select[name="brand"]').get(0).selectedIndex=0;
		$('select[name="people_style"]').get(0).selectedIndex=0;
		$('select[name="people_style"]').get(0).selectedIndex=0;
		$('select[name="goods_style"]').html('<option value="">按风格筛选</option>');
		$('select[name="status"]').get(0).selectedIndex=0;		
		var data ={};
		data['page']=1;
		data['pagelimit']=pagelimit;		
		data['token']=token;
		data['ordercolum']=name;
		data['ordertype']=sorttype;
		$.ajax({
			type:"post",
			url:"http://ww.yc630.com/api/index.php/Seller/Goods/goodsList",
			data:data,
			dataType:'json',
			success:function(phpdata){
				//分页
			    pages(phpdata['data']['count'],pagelimit);
				
				var str = '<tr class="z_head"><td>序号</td><td>商品ID</td><td>商品名称</td><td>价格</td><td>品牌</td><td>人群</td><td>风格</td><td id="store_nu">库存↑↓</td><td id="sell_nu">累计销量↑↓</td><td id="viewnu">浏览次数↑↓</td><td id="purchase_nu">加入购物车↑↓</td><td id="saved">收藏</td><td>状态</td><td>操作</td></tr>';
			if(phpdata['data']['count']==0){					
				str += '<tr><td colspan="14" style="color:#999">暂无搜索结果</td></tr>';
				$('.z_t').html(str);
				return false;
			}
			for(i in phpdata['data']['goods']){
				j=i*1+1*1;
				var status_name = '';
				var make = '';
				if(phpdata['data']['goods'][i]['status'] == 0){
					var status_name = '未提交';
					var make = '<a onclick="gcommit(this)">提交</a> <a onclick="edit(this)">编辑</a> <a onclick="delet(this)">删除</a>'
				}
				if(phpdata['data']['goods'][i]['status']==1){
					var status_name = '审核中';
					var make = '<a onclick="edit(this)">编辑</a> <a onclick="delet(this)">删除</a>';
				}
				if(phpdata['data']['goods'][i]['status']==2){
					var status_name = '未通过';
					var make = '<a onclick="edit(this)">编辑</a> <a onclick="delet(this)">删除</a>';
				}
				if(phpdata['data']['goods'][i]['status']==3){
					var status_name = '代售';
					var make = '<a onclick="sj(this)">上架</a> <a onclick="edit(this)">编辑</a> <a onclick="delet(this)">删除</a>';
				}
				if(phpdata['data']['goods'][i]['status']==4){
					var status_name = '已上架';
					var make = '<a onclick="xj(this)">下架</a> <a onclick="edit(this)">编辑</a> <a onclick="delet(this)">删除</a>';
				}
				if(phpdata['data']['goods'][i]['status']==5){
					var status_name = '已下架';
					var make = '<a onclick="sj(this)">上架</a> <a onclick="edit(this)">编辑</a> <a onclick="delet(this)">删除</a>';
				}
				if(phpdata['data']['goods'][i]['status']==6){
					var status_name = '被删除';
					var make = '';
				}
				str += '<tr class="z_list_main"><td>'+j+'</td><td>'+phpdata['data']['goods'][i]['id']+'</td><td>'+phpdata['data']['goods'][i]['goods_name']+'</td><td>'+phpdata['data']['goods'][i]['min_price']+'-'+phpdata['data']['goods'][i]['max_price']+'</td><td>'+phpdata['data']['goods'][i]['brand_name']+'</td><td>'+phpdata['data']['goods'][i]['people_style_name']+'</td><td>'+phpdata['data']['goods'][i]['goods_style_name']+'</td><td>'+phpdata['data']['goods'][i]['store_nu']+'</td><td>'+phpdata['data']['goods'][i]['sell_nu']+'</td><td>'+phpdata['data']['goods'][i]['viewnu']+'</td><td>'+phpdata['data']['goods'][i]['purchase_nu']+'</td><td>'+phpdata['data']['goods'][i]['notice_nu']+'</td><td>'+status_name+'</td><td>'+make+'</td></tr>';
			}
			$('.z_t').html(str);
			}
		});

	}
     
     document.cookie="store_nu=1";
     document.cookie="sell_nu=1";
     document.cookie="viewnu=1";
     document.cookie="purchase_nu=1";
     document.cookie="sort=0";
     
	//库存排序
	$('.z_t').on('click','#store_nu',function(){
		var store_nu= getCookie("store_nu");
		document.cookie="sort=store_nu";
		if(store_nu==1){
          sort('store_nu','desc');
          document.cookie="store_nu=2";
		}else{
			sort('store_nu','asc');
			document.cookie="store_nu=1";
		}
	})

	//销量排序
	$('.z_t').on('click','#sell_nu',function(){
		var sell_nu= getCookie("sell_nu");
		document.cookie="sort=sell_nu";
		if(sell_nu==1){
          sort('sell_nu','desc');
          document.cookie="sell_nu=2";
		}else{
			sort('sell_nu','asc');
			document.cookie="sell_nu=1";
		}
	})

	//购物车排序
	$('.z_t').on('click','#purchase_nu',function(){
		var purchase_nu= getCookie("purchase_nu");
		document.cookie="sort=purchase_nu";
		if(purchase_nu==1){
          sort('purchase_nu','desc');
          document.cookie="purchase_nu=2";
		}else{
			sort('purchase_nu','asc');
			document.cookie="purchase_nu=1";
		}
	})
	//浏览次数排序
	$('.z_t').on('click','#viewnu',function(){
		var viewnu= getCookie("viewnu");
		document.cookie="sort=purchase_nu";
		if(viewnu==1){
          sort('viewnu','desc');
          document.cookie="viewnu=2";
		}else{
			sort('viewnu','asc');
			document.cookie="viewnu=1";
		}
	})
	

})
//编辑
function edit(obj){
	var id=$(obj).parent().parent().children().eq(1).html()
	window.location.href="goods_edit.html?id="+id+""
}
//下架
function xj(obj){
	$(".mask_wrap").show()
	$("#xjia").show()
	$(".qd").click(function(){
		var id=$(obj).parent().parent().children().eq(1).html()
		$.ajax({
			type:"post",
			url:"http://ww.yc630.com/api/index.php/Seller/Goods/goods_down",
			data:{
				"id":id,
				'token':token
			},
			dataType:'json',
			success:function(phpdata){
				window.location.reload();
			}
		})
	})
	$(".qx").click(function(){
		$(".mask_wrap").hide()
		$("#tijiao").hide()
	})
}
//上架
function sj(obj){
	$(".mask_wrap").show()
	$("#sjia").show()
	$(".qd").click(function(){
		var id=$(obj).parent().parent().children().eq(1).html()
		$.ajax({
			type:"post",
			url:"http://ww.yc630.com/api/index.php/Seller/Goods/goods_up",
			data:{
				"id":id,
				'token':token
			},
			dataType:'json',
			success:function(phpdata){
				window.location.reload();
			}
		})
	})
	$(".qx").click(function(){
		$(".mask_wrap").hide()
		$("#tijiao").hide()
	})
}
//提交
function gcommit(obj){
	$(".mask_wrap").show()
	$("#tijiao").show()
	$(".qd").click(function(){
		var id=$(obj).parent().parent().children().eq(1).html()
		$.ajax({
			type:"post",
			url:"http://ww.yc630.com/api/index.php/Seller/Goods/goods_commit",
			data:{
				"id":id,
				'token':token
			},
			dataType:'json',
			success:function(phpdata){
				window.location.reload();
			}
		})
	})
	$(".qx").click(function(){
		$(".mask_wrap").hide()
		$("#tijiao").hide()
	})
}
//删除
function delet(obj){
	$(".mask_wrap").show()
	$("#schu").show()
	$(".qd").click(function(){
		var id=$(obj).parent().parent().children().eq(1).html()
		$.ajax({
			type:"post",
			url:"http://ww.yc630.com/api/index.php/Seller/Goods/goods_delete",
			data:{
				"id":id,
				'token':token
			},
			dataType:'json',
			success:function(phpdata){
				$(obj).parent().parent().remove()
				window.location.reload();
			}
		})
	})
	$(".qx").click(function(){
		$(".mask_wrap").hide()
		$("#tijiao").hide()
	})
}

